import matplotlib.pyplot as plt
import numpy as np

# Sample data
webshop_scores = [0.8830727396329028, 0.8338557993730408, 0.7816091954022989]
# hotpotQA_scores = [0.8713892709766162, 0.60, 0.59]
hotpotQA_scores = [0.8713892709766162, 0.67, 0.64]

# Bar properties
bar_width = 0.35
index = np.arange(3)  # Number of groups

# Create the plot
plt.figure(figsize=(8, 6))

# Plot bars for Webshop and HotpotQA
plt.bar(index, webshop_scores, bar_width, label='Webshop', color="#1f77b4", edgecolor='black')
plt.bar(index + bar_width, hotpotQA_scores, bar_width, label='HotpotQA', color="#ff7f0e", edgecolor='black', hatch='//')

# Add labels and ticks
plt.xlabel('Dataset Type', fontsize=22)
plt.ylabel('Preference ACC', fontsize=22)
plt.xticks(index + bar_width / 2, ('Training', 'IND Test', 'OOD Test'), fontsize=22)
plt.yticks(np.arange(0.5, 1.0, 0.1), fontsize=22)

# Set y-axis limit
plt.ylim(0.5, 0.9)

# Remove top and right spines
ax = plt.gca()
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)

# Add gridlines
plt.grid(axis='y', linestyle='--', alpha=0.7)

# Add a legend
plt.legend(loc='upper left', bbox_to_anchor=(0.6, 1), fontsize=18)

# Optimize layout
plt.tight_layout()

# Save the plot to a file
plt.savefig('plot/preference_ACC.png', format='png', dpi=300)

# Show the plot
plt.show()
